#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //创建菜单栏
    QMenuBar *menu_bar=new QMenuBar();
    //将这个菜单栏添加到主窗口中
    this->setMenuBar(menu_bar);
    //构建菜单对象并设置快捷键
    QMenu *menu1=new QMenu("菜单1 (&A)");
    QMenu *menu2=new QMenu("菜单2 (&B)");
    QMenu *menu3=new QMenu("菜单3 (&C)");
    //将菜单对象添加到菜单栏中
    menu_bar->addMenu(menu1);
    menu_bar->addMenu(menu2);
    menu_bar->addMenu(menu3);
    //构建菜单项对象
    QAction *action1=new QAction("菜单项1 (&D)");
    QAction *action2=new QAction("菜单项2 (&E)");
    QAction *action3=new QAction("菜单项3 (&F)");
    //给菜单添加菜单项
    menu1->addAction(action1);
    menu2->addAction(action2);
    menu3->addAction(action3);
    //为菜单项1点击后，设置槽函数测试
    connect(action1,&QAction::triggered,this,&MainWindow::handler_test);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handler_test()
{
    qDebug()<<"菜单项1-触发";
}

